package com.ccjk.beusoft.plugin.host;

import android.app.Activity;
import android.os.Bundle;

import com.ccjk.beusoft.hot.plugin.Bind;
import com.ccjk.beusoft.hot.plugin.Const;
import com.ccjk.beusoft.hot.plugin.PluginActivityInterface;
import com.ccjk.beusoft.hot.plugin.PluginPackage;

import java.lang.reflect.Constructor;

/**
 * Created by CCJK on 2017/12/2.
 */

public class Util {
    public static void startActivity(Activity proxyActivity, PluginPackage pluginPackage, String activityClassNme) {
        try {
            Class<?> activityClass = pluginPackage.getPluginClassLoader().loadClass(activityClassNme);
            Constructor constructor = activityClass.getConstructor(new Class[]{});
            Object activity = constructor.newInstance(new Object[]{});
            PluginActivityInterface pluginActivityInterface = (PluginActivityInterface) activity;
            pluginActivityInterface.bind(proxyActivity, pluginPackage);
            ((Bind) proxyActivity).bind((Activity) pluginActivityInterface, pluginPackage);
            Bundle bundle = new Bundle();

            bundle.putInt(Const.INSTANCE.getKEY_ACTIVITY_FROM(), Const.INSTANCE.getFROM_INTERNAL());
            pluginActivityInterface.onCreate(bundle);
        } catch (Exception e) {
            e.printStackTrace();

        }

    }
}
